home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / AIAT / Headers / Accessor / TWVector.h < prev    next >
Encoding:
Text File  |  1998-04-16  |  2.9 KB  |  91 lines  |  [TEXT/CWIE]

  1. // TWVector.h
  2. //    Copyright:    © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
  3. #pragma once
  4. #ifndef TWVector_h
  5. #define TWVector_h
  6.  
  7. #pragma import on
  8.  
  9. #if PRAGMA_STRUCT_ALIGN
  10.     #pragma options align=power
  11. #endif
  12.  
  13. #include "TermIndex.h"
  14.  
  15. #pragma IA_BEGIN_EXPORTS
  16.  
  17. // TWComponent: what TWVector's are made of.
  18. struct TWComponent {
  19.     TermID            termID;                // the TermID
  20.     float            weight;                // the normalized weight of the term
  21. private:
  22.     void*            operator new(size_t size);        // stack or array allocate only
  23. };
  24.  
  25. // TWVector: available from a VectorAccessor.
  26. class TWVector : public IAObject {
  27. public:
  28.                     TWVector(DocLength l);
  29.                     ~TWVector();
  30.     
  31.     float            Similarity(TWVector* other);
  32.     void            Normalize();
  33.  
  34.     TWVector*        Sum(TWVector* other);
  35.     
  36.     void            SetDocumentLength(DocLength l) {length = l;}
  37.     void             SetComponents(TWComponent* c) {components = c;}
  38.     DocLength        GetDocumentLength() const {return length;}
  39.     TWComponent*    GetComponents() const {return components;}
  40.     
  41.     bool             HasNegativeComponents() const;
  42.     IABlockSize     StoreSize() const;
  43.     TWVector*        DeepCopy() const;
  44.     void             Store( IAOutputBlock *output ) const;
  45.     TWVector*        Restore( IAInputBlock *input ) const;
  46.     
  47. // SortByTerm is the normal ordering for the vectors
  48.     void             SortByTerm();     
  49. // SortByWeight is a special ordering for the vectors to be used
  50. //    during human-output and truncation operations it sorts by size of the component
  51.     void             SortByWeight();
  52. // SortByAbsoluteWeight is a special ordering for the vectors to be used during human-output 
  53. // and truncation operations it sorts by absolute value of the component weight
  54.     void             SortByAbsoluteWeight();
  55. // Truncate removes the terms with the lowest weights until maxTerms or fewer are left
  56.     void            Truncate(uint32 maxTerms );
  57. // TruncateByAbsoluteValue removes the terms with the lowest absolute weights until maxTerms or fewer are left
  58.     void             TruncateByAbsoluteValue(uint32 maxTerms );
  59.  
  60. // This is a cluster centroid representing totalVectorCount-1 other vectors.
  61. // The parameter is a new vector to be incorporated into this (the centroid).
  62. // The new centroid is returned.
  63. // The formula: result = (n-1/n)*this + (1/n)*newVector
  64.     TWVector*         AddIntoAverage(const TWVector *newVector, 
  65.                                     uint32 totalVectorCount, bool invertSecondVector = false);
  66. // returns a NEW TWVector, does not allow negative components in vector.
  67.     TWVector*        AddWeighted(const TWVector *vector, 
  68.                                     float weightFactor1, float weightFactor2);
  69. // returns a NEW TWVector, DOES INDEED allow negative components in vector.                                    
  70.     TWVector*         AddWeightedAllowNegatives(const TWVector *vector, 
  71.                                     float weightFactor1, float weightFactor2);
  72.  
  73. //    bool            Equal(TWVector* other);
  74.  
  75. private:
  76.                     TWVector(TWVector&);
  77.     DocLength        length;                // the number of components in the vector
  78.     TWComponent*    components;            // an array of TWComponents
  79.  
  80. };
  81.  
  82. #pragma IA_END_EXPORTS
  83.  
  84. #if PRAGMA_STRUCT_ALIGN
  85.     #pragma options align=reset
  86. #endif
  87.  
  88. #pragma import reset
  89.  
  90. #endif
  91.